package com.wang.service.Impl;

import com.wang.dao.ExpertEntityDao;
import com.wang.dao.UserEntityDao;
import com.wang.domain.ExpertEntity;
import com.wang.domain.UserEntity;
import com.wang.service.IExpertService;
import com.wang.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/2/11 0011.
 */
@Service
public class ExpertServiceImpl implements IExpertService {
    @Autowired
    private ExpertEntityDao expertDao;

    @Override
    public ExpertEntity findByName(String name) {
        return expertDao.findByName(name) ;
    }

    @Override
    public List<ExpertEntity> selectRandoms(int type , int limit) {
        return expertDao.selectRandoms(type, limit);
    }


    @Override
    public Page<ExpertEntity> findAll(int pageNo, int pageSize) {
        return expertDao.findAll(new PageRequest(pageNo,pageSize, Sort.Direction.ASC,"id"));
    }

    @Override
    public Page<ExpertEntity> findAll() {
        return findAll(0,Integer.MAX_VALUE);
    }

    @Override
    public ExpertEntity add(ExpertEntity entity) {
        return expertDao.save(entity);
    }

    @Override
    public ExpertEntity edit(ExpertEntity entity) {
        return expertDao.save(entity);
    }

    @Override
    public void delete(ExpertEntity entity) {
        expertDao.delete(entity);
    }
}
